

/**
 * 雨天气
 */

import RainShader from '../shader/RainShader.glsl?raw'
import { v4 as uuid } from 'uuid'

export default class RaderScan {
  /**
   * 
   * @param {*} viewer 
   * @param {*} options 
   */

  constructor(viewer, options = {}) {
    this._viewer = viewer
    this._delegate = undefined
    this._speed = options.speed || 10.
  }


  mounted() {
    this._delegate = new Cesium.PostProcessStage({
      name: uuid(),
      fragmentShader: RainShader,
      uniforms: {
        speed: this._speed
      }
    })
    
  }

  /**
   * 添加后处理效果
   * @returns 
   */

  start() {
    !this._delegate && this.mounted()
    this._delegate && this._viewer.scene.postProcessStages.add(this._delegate)
    return this
  }

  /**
   * 停止渲染
   */

  stop() {
    this._delegate && this._viewer.scene.postProcessStages.remove(this._delegate)
    this._delegate = undefined
  }

  set speed(speed) {
    this._speed = speed
    this._delegate && (this._delegate.uniforms.speed = speed)
    return this
  }

  get speed() {
    return this._speed
  }

}
